import {Toast} from "vant";
import {get, queryIP} from '@/js/sys/axios';
import {ref, reactive} from "vue";

export default {
    data: reactive({
        numberKeyboardShow: false,
        network: {
            show: false,
            _ip1: 14,
            _ip2: 112,
            _ip3: 0,
            _ip4: 0,
            uri: "/wwl/getToken",
            ip: ""
        },
        imagess:[
            "http://14.112.66.42:9090/home/jpg/3.jpg",
            "http://14.112.66.42:9090/home/jpg/3.jpg"
        ]
    }),
    get: () => get("common/get"),
    message: (message, position, overlay, type) => {
        Toast({
            type: type ? type : null,                                    //提示类型，可选值为 loading success fail html
            message: message,                                        //文字消息
            position: position ? position : null,                       //展示位置：top、bottom
            overlay: overlay ? overlay : false,                        //屏幕遮罩层
        })
    },
    //查询IP功能
    queryIP: async (data) => {

        let n = data.network;
        let br = 1;
        for (let i = n._ip3; i < 255; i++) {

            for (let j = n._ip4; j < 255; j++) {
                let result = queryIP(n._ip1, n._ip2, i, j, n.uri);
                result.then((success) => {
                    if (success && success.code != "ERR_NETWORK") {
                        br = 2;
                        n.ip = i + "." + j;
                    }
                })
                //等待时间 毫秒值
                await new Promise(r => setTimeout(r, 80))
            }

            if (br == 2) {
                break;
            }
            //等待时间 毫秒值
            await new Promise(r => setTimeout(r, 822))

        }
    }


}